<template>
  <div class="dd-container">
    <div class="ddc-header">
      <img class="dd-text" src="../../assets/images/DueDiligence/dd-text.png" alt="">
      <div class="search">
        <div class="search-content">
          <input class="search-input" @keyup.enter="searchHander" v-model="search" placeholder="请输入企业名称或统一社会信用代码" />
          <div class="btn" @click="searchHander">
            <img src="../../assets/images/DueDiligence/search.png" alt="">
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, reactive, onMounted, computed } from "vue"
import { useRouter } from "vue-router"
import { useDueDiligenceStore } from "../../stores/modules/DueDiligence"
import { getDueDiligenceSearch } from "../../api/DueDiligence"
import { ElMessage, ElLoading } from 'element-plus'

let loading = null
const router = useRouter()
const dueDiligenceStore = useDueDiligenceStore()
const search = ref('')

const httpDueDiligenceSearch = (companyName) => {
  loading = ElLoading.service({
    lock: true,
    text: 'Loading',
    background: 'rgba(0, 0, 0, 0.7)',
  })
  getDueDiligenceSearch({
    keyword: companyName
  }).then(res => {
    loading.close()
    dueDiligenceStore.companyName = res.data.name
    dueDiligenceStore.keyNo = res.data.creditCode
    dueDiligenceStore.creditCode = res.data.creditCode
    router.push("/DDReportType")
  }).catch(error => {
    loading.close()
    ElMessage({ message: "公司不存在", type: 'error', duration: 5 * 1000 })
  })
}

const searchHander = () => {
  if (search.value) {
    httpDueDiligenceSearch(search.value)
  }
}



</script>
<style lang="less" scoped>
.dd-container {
  background: #fff;
  height: calc(100vh - 70px);
  background: url("../../assets/images/DueDiligence/dd-bg.png") no-repeat;
  background-size: cover;

  .ddc-header {
    width: 100%;
    text-align: center;

    .dd-text {
      width: 500px;
      padding-top: 50px;
    }

    .search {
      width: 80%;
      height: 130px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 0 auto;

      .search-content {
        width: 80%;
        display: flex;

        .search-input {
          flex: 1;
          height: 70px;
          outline: none !important;
          padding-left: 20px;
          box-sizing: border-box;
          font-size: 18px;
          border-top-left-radius: 10px;
          border-bottom-left-radius: 10px;
          border: 2px solid #536EF7;
        }

        .btn {
          width: 150px;
          height: 70px;
          background-color: #536EF7;
          display: flex;
          align-items: center;
          justify-content: center;
          border-top-right-radius: 10px;
          border-bottom-right-radius: 10px;

          img {
            width: 25px;
            height: 25px;
            margin-right: 10px;
          }

          span {
            font-weight: bold;
            font-size: 20px;
            color: #FFFFFF;
          }
        }
      }
    }
  }
}
</style>
